import threading
from queue import Queue

class ThreadPool:
    def __init__(self, num_threads):
        self.queue = Queue()
        for _ in range(num_threads):
            threading.Thread(target=self.worker, daemon=True).start()

    def worker(self):
        while True:
            task = self.queue.get()
            if task is None:
                break
            task()
            self.queue.task_done()

    def submit(self, task):
        self.queue.put(task)